unit uBorder;

interface

uses Graphics;  

type
  TBorder = class
  private

  public
    TL, DL, TR, DR, THL, LVL, DHL, RVL: TBitMap;
    procedure Make(AImage: TBitMap);
    constructor Create(Path: string);
    destructor Destroy; override;
  end;

implementation

uses SysUtils;

{ TBorder }

constructor TBorder.Create(Path: string);
begin
  THL := TBitMap.Create;
  THL.LoadFromFile(Path + 'THL.bmp');
  DHL := TBitMap.Create;
  DHL.LoadFromFile(Path + 'DHL.bmp');
  LVL := TBitMap.Create;
  LVL.LoadFromFile(Path + 'LVL.bmp');
  RVL := TBitMap.Create;
  RVL.LoadFromFile(Path + 'RVL.bmp');
  DR := TBitMap.Create;
  DR.Transparent := True;
  DR.TransparentColor := clFuchsia;
  DR.LoadFromFile(Path + 'DR.bmp');
  TR := TBitMap.Create;
  TR.Transparent := True;
  TR.TransparentColor := clFuchsia;
  TR.LoadFromFile(Path + 'TR.bmp');
  DL := TBitMap.Create;
  DL.Transparent := True;
  DL.TransparentColor := clFuchsia;
  DL.LoadFromFile(Path + 'DL.bmp');
  TL := TBitMap.Create;
  TL.LoadFromFile(Path + 'TL.bmp');
  TL.TransparentColor := clFuchsia;
  TL.Transparent := True;
end;

destructor TBorder.Destroy;
begin
  THL.Free;
  DHL.Free;
  LVL.Free;
  RVL.Free;
  TL.Free;
  DL.Free;
  TR.Free;   
  DR.Free;
  inherited;  
end;

procedure TBorder.Make(AImage: TBitMap);
var
  C: Word;
  B: TBitmap;   
begin
  B := TBitMap.Create;         
  try
    B.Assign(AImage);
     
    C := TL.Width;
    while (C < AImage.Width - THL.Width) do   
    begin
      B.Canvas.Draw(C, 0, THL);  
      B.Canvas.Draw(C, AImage.Height - DHL.Height, DHL);  
      Inc(C, THL.Width);
    end;
    C := TL.Height;
    while (C < AImage.Height - LVL.Height) do
    begin
      B.Canvas.Draw(0, C, LVL);  
      B.Canvas.Draw(AImage.Width - RVL.Width, C, RVL);  
      Inc(C, LVL.Height);
    end;
    B.Canvas.Draw(0, 0, TL);
    B.Canvas.Draw(0, AImage.Height - DL.Height, DL);
    B.Canvas.Draw(AImage.Width - TR.Width, 0, TR);
    B.Canvas.Draw(AImage.Width - DR.Width, 
      AImage.Height - DR.Height, DR); 
    AImage.Assign(B);
  finally
    FreeAndNil(B);
  end;
end;

end.
